<template>
  <div class="product-ranking-warp">
    <div class="product-ranking-title">
      <h3>生产排行榜（{{new Date().valueOf().toDateString('yyyy-MM-dd')}}）</h3>
      <a href="javascript:;" @click="toWorkLog">更多 &gt</a>
    </div>

    <div class="ranking-list-warp">
      <ul>
        <li class="ranking-header">
          <span>排名</span>
          <span class="product-name">产品</span>
          <span>占比</span>
        </li>
        <li class="ranking-item" v-for="(ranking,index) in rankings" :key="index">
          <span>{{index+1}}</span>
          <span class="product-name">{{ranking.id}}</span>
          <span><el-progress style="width: 100%;" :percentage="parseInt(ranking.name/sumTotal*100)"></el-progress></span>
        </li>
      </ul>
    </div>

  </div>
</template>

<script>
  export default ({
    props:['json'],
    data(){
      return {
        rankings:[],
        sumTotal:null,
      }
    },
    watch:{
      'json':{
        deep:true,
        handler(val){
          let sum=null;
          val=val||[];
          val.forEach((item)=>{
            item.name=parseInt(item.name);
            sum+=item.name;
          });
          this.sumTotal=sum;
          this.rankings=val;
        }
      }
    },
    methods:{
      toWorkLog(){
        this.$router.push('/info/codeLog');
      }
    }

  })
</script>

<style scoped>
  .product-ranking-warp{
    width: 450px;
    margin-top: 20px;
    border: 1px solid #e8e8e8;
    border-radius: 5px;
  }
  .product-ranking-title{
    display: flex;
    justify-content: space-between;
    height: 40px;
    line-height: 40px;
    font-size: 16px;
    color: #333;
    border-bottom: 1px solid #e8e8e8;
  }
  .product-ranking-title h3{
    margin-left: 20px;
  }
  .product-ranking-title a{
    font-size: 12px;
    color: #0e83e6;
    margin-right: 20px;
    cursor: pointer;
  }
  .ranking-list-warp{
    width: 100%;
    font-size: 14px;
    padding-top: 30px;
    color: #666;
  }
  .ranking-list-warp ul{
    margin: 0 auto;
    height: 280px;
    width: 386px;
  }
  /*.ranking-header{
    text-align: center;
  }*/
  .ranking-list-warp li{
    display: flex;
    border-bottom: 1px solid #e8e8e8;
  }
  .ranking-list-warp li span{
    width: 120px;
    height: 36px;
    line-height: 36px;
  }
  .ranking-list-warp .product-name{
    width: 348px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .ranking-list-warp li span:last-child{
    width: 100%;
  }
  .ranking-item span:last-child{
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: center;
  }
</style>
